#include "piece.h"

//Implementation of class Piece
/* 0 represents white, 1 represents black */

Piece::Piece(int color, string type, QWidget *parent)
: QPushButton(parent)
, color(color)
, type(type)
{
    this->setStyleSheet("QPushButton{border: 0px}");
    this->setFixedSize(80, 80);

    //load the picture
    string imgPath(":/img/.png");

    //convert all alphabets to lower
    transform(type.begin(), type.end(), type.begin(), [=](char c){
        return tolower(c);
    });

    //convert the first alphabet to upper
    type[0] = toupper(*type.begin());

    if(color == 0)  imgPath.insert(6, "White" + type);
    if(color == 1)  imgPath.insert(6, "Black" + type);

    //set picture for piece
    img.load(imgPath.c_str());
    this->setIconSize(QSize(this->width(), this->height()));
    this->setIcon(img);

    connect(this, &QPushButton::clicked, [=](){
        qDebug() << imgPath.c_str() << " has clicked";
    });
}


void Piece::moveTo(int x, int y){
    this->setGeometry(x, y, 80, 80);
}

void Piece::setNumber(int num){
    this->number = num;
}
